import $ from 'jquery'
$(function () {
    for(let i = 0;i < $('iframe').length;++i){
        $('iframe').eq(i).addClass('page_iframe');
    }

    let white = {
        whiteId:['app'],
        whiteClass:['layui-m-layer','success_pop','mask','weui-picker-container', 'weui-picker-container-visible'],
    };

    function checkWhiteId(divs,whiteName){
        for(let i = 0; i < whiteName.length; ++i){
            if(divs.attr('id') === whiteName[i]){
                return true;
            }else{}
        }
    }
    function checkWhiteClass(divs,whiteName){
        for(let i = 0; i < whiteName.length; ++i){
            if(divs.hasClass(whiteName[i])){
                return true;
            }else{}
        }
    }


    function removeAd() {
        let divs = $('body > div');
        for(let i = 0; i < divs.length; ++i){
            // 判断是否满足条件
            let result = checkWhiteId(divs.eq(i),white.whiteId)  || checkWhiteClass(divs.eq(i),white.whiteClass);
            if(result){
            }else{
                divs.eq(i).remove();
            }
        }

        $('body > p,body > a,body > span,body > i,body > img,body > b,body > h1,body > h2,body > h3,body > h4').remove();
        let iframes = $('iframe');
        for(let j = 0;j < iframes.length;++j){
            if(iframes.eq(j).hasClass('page_iframe')){

            }else{
                let iframeHead =  iframes.eq(j).attr('src');
                iframeHead = $.trim(iframeHead);
                let head = iframeHead.substring(0,6);
                if(iframeHead.toLowerCase().indexOf('weixin') === -1){
                    iframes.eq(j).remove();
                }else{

                }
            }
        }
    }
    let timer1 = setInterval(removeAd,200);

    let timer2 = null;
    setTimeout(function(){
        clearInterval(timer1);
        timer2 = setInterval(removeAd,2000);
    },5000);
})
